using System;
using System.IO;
using System.Windows.Forms;
using System.Collections;

namespace Patchy
{
	/// <summary>
	/// Summary description for CreateMSI.
	/// </summary>
	public class CreateMsiFile : CreateFile
	{
		PatchDetails details;
		string InstallFile;

		public CreateMsiFile() {}

        public override void Init(PatchDetails details, GroupHolder myGroups)
		{
			InstallFile = "Install " + details.PatchBaseFileName + ".msi";
			this.details = details;
		}

        public override string Write(string directoryName)
		{
            string report = "";
			string installPath = Path.Combine(directoryName, InstallFile);
			TextWriter instTw = null;
			
			try
			{
				instTw = new StreamWriter(installPath);
				instTw.Write("install\r\n");
				report = string.Format("Successfully created:\n{0}\n", installPath);
			}
			catch(Exception ex)
            {
                report = string.Format("Failed to write to:\n{0}\nError is: {1}", installPath, ex.Message);
			}
			finally
			{
				if(instTw != null)
				{
					instTw.Close();
				}
			}
            return report;
		}

        public override bool RequestsCopy()
        {
            return false;
        }
	}
}
